<?php
namespace Home\Controller;
use Think\Controller;
class CatController extends Controller {
    public function cat(){
    	$goods = D("Admin/goods");
    	 
    	$count = count($goods->field('goods_id,goods_name,shop_price,goods_img,market_price')->where("cat_id=".I("cat_id"))->order("goods_id DESC")->select());
         // 查询满足要求的总记录数
         $Page = new \Think\Page($count,16);// 实例化分页类 传入总记录数和每页显示的记录数(16)
        $show = $Page->show();
        $gd = $goods->field('goods_id,goods_name,shop_price,goods_img,market_price')->where("cat_id=".I("cat_id"))->order("goods_id DESC")->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign("goodslist",$gd);
        $this->assign("mbx",$this->brand(I("cat_id")));
        $hisotry = array_reverse(session("hisotry"),true);
        $this->assign("hot",$hisotry);
    	$this->assign("show",$show);
    	$this->assign("count",$count);
        $this->display();
    }
    /*
     *商品面包屑
     */
    public function brand($catId)
    {
      $cat = D("Admin/cat");
      while($catId >0){
        foreach ($cat->order("cat_id ASC")->select() as $k => $v) 
        {
          if($catId == $v['cat_id']){
            $arr[$catId]=$v;
            $catId=$v['parent_id'];
          }
        }

      }
      return array_reverse($arr);
    }
}